<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/User.Master" Inherits="System.Web.Mvc.ViewPage" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>

<script runat="server">

    protected void Page_Load(object sender, EventArgs e)
    {
        lbUsername.Text = "" + ViewData["UserName"];
    }


    protected void DetailsView1_DataBound(object sender, EventArgs e)
    {
        Label a = DetailsView1.FindControl("Gender") as Label;
        Label a1 = DetailsView1.FindControl("lbGender") as Label;
        if (a != null && a1 != null)
        {
            if (a.Text == "1")
            {
                a1.Text = "Male";
            }
            if (a.Text == "0")
            {
                a1.Text = "Female";
            }
        }
    }
</script>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    EditProfile
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <h1>
        Profile<asp:Label ID="lbUsername" runat="server" Visible="False"></asp:Label>
    </h1>
    <p>
        <asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" CellPadding="4"
            DataSourceID="SqlDataSource1" ForeColor="#333333" GridLines="None" Height="50px"
            Width="459px" AllowPaging="True" DataKeyNames="ID" 
            OnDataBound="DetailsView1_DataBound">
            <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
            <CommandRowStyle BackColor="#E2DED6" Font-Bold="True" />
            <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
            <FieldHeaderStyle BackColor="#E9ECF1" Font-Bold="True" />
            <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
            <Fields>
                <asp:BoundField DataField="ID" HeaderText="ID" SortExpression="ID" InsertVisible="False"
                    ReadOnly="True" />
                <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
                <asp:BoundField DataField="DateOfBirth" HeaderText="Date Of Birth" 
                    SortExpression="DateOfBirth" />
                <asp:BoundField DataField="PlaceOfBirth" HeaderText="Place Of Birth" 
                    SortExpression="PlaceOfBirth" />
                <asp:TemplateField HeaderText="Gender" SortExpression="Gender">
                    <EditItemTemplate>
                        <asp:DropDownList ID="DropDownList1" runat="server" SelectedValue='<%# Bind("Gender") %>'>
                            <asp:ListItem Value="1">Male</asp:ListItem>
                            <asp:ListItem Value="0">Female</asp:ListItem>
                        </asp:DropDownList>
                    </EditItemTemplate>
                    <InsertItemTemplate>
                        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
                    </InsertItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="Gender" runat="server" Text='<%# Bind("Gender") %>' 
                            Visible="False"></asp:Label>
                        <asp:Label ID="lbGender" runat="server" Text="Label"></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:BoundField DataField="Degree" HeaderText="Degree" SortExpression="Degree" />
                <asp:BoundField DataField="Role" HeaderText="Role" SortExpression="Role" />
                <asp:TemplateField HeaderText="Major" SortExpression="MajorID">
                    <EditItemTemplate>
                        <asp:DropDownList ID="DropDownList2" runat="server" DataSourceID="SqlDataSource1"
                            DataTextField="Name" DataValueField="ID" SelectedValue='<%# Bind("MajorID") %>'>
                        </asp:DropDownList>
                        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:CDIO1ConnectionString %>"
                            SelectCommand="SELECT [Name], [ID] FROM [Major]"></asp:SqlDataSource>
                    </EditItemTemplate>
                    <InsertItemTemplate>
                        <asp:DropDownList ID="DropDownList2" runat="server" DataSourceID="SqlDataSource1"
                            DataTextField="Name" DataValueField="ID" SelectedValue='<%# Bind("MajorID") %>'>
                        </asp:DropDownList>
                        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:CDIO1ConnectionString %>"
                            SelectCommand="SELECT [Name], [ID] FROM [Major]"></asp:SqlDataSource>
                    </InsertItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="lbMajor" runat="server" Text='<%# Bind("Major") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:BoundField DataField="UniOfGrad" HeaderText="University Of Graduate" 
                    SortExpression="UniOfGrad" />
                <asp:BoundField DataField="YearOfGrad" HeaderText="Year Of Graduate" 
                    SortExpression="YearOfGrad" />
                <asp:BoundField DataField="PlaceOfMsc" 
                    HeaderText="Place Of Master Degree Issue" SortExpression="PlaceOfMsc" />
                <asp:BoundField DataField="YearOfMsc" HeaderText="Year Of Master Degree Issue" 
                    SortExpression="YearOfMsc" />
                <asp:BoundField DataField="PlaceOfPhd" 
                    HeaderText="Place Of Physical Doctor Degree Issue" 
                    SortExpression="PlaceOfPhd" />
                <asp:BoundField DataField="YearOfPhd" 
                    HeaderText="Year Of Physical Doctor Degree Issue" SortExpression="YearOfPhd" />
                <asp:BoundField DataField="Language" HeaderText="Language" SortExpression="Language" />
                <asp:BoundField DataField="Address" HeaderText="Address" SortExpression="Address" />
                <asp:BoundField DataField="Email" HeaderText="Email" SortExpression="Email" />
                <asp:BoundField DataField="Phone" HeaderText="Phone" SortExpression="Phone" />
                <asp:CommandField ShowEditButton="True" />
            </Fields>
            <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
            <EditRowStyle BackColor="#999999" />
            <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
        </asp:DetailsView>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:CDIO1ConnectionString %>"
            SelectCommand="SELECT Professor.ID, Professor.AccountID, Professor.Name, Professor.DateOfBirth, Professor.PlaceOfBirth, Professor.Gender, Professor.Degree, Professor.UniOfGrad, Professor.YearOfGrad, Professor.PlaceOfMsc, Professor.YearOfMsc, Professor.PlaceOfPhd, Professor.YearOfPhd, Professor.Language, Professor.Role, Professor.MajorID, Professor.Address, Professor.Phone, Professor.Email, Professor.Status, Major.Name AS Major FROM Professor INNER JOIN Account ON Professor.AccountID = Account.ID INNER JOIN Major ON Professor.MajorID = Major.ID WHERE (Account.Username = @Username)"
            UpdateCommand="UPDATE Professor SET Name = @Name, DateOfBirth = @DateOfBirth, PlaceOfBirth = @PlaceOfBirth, Degree = @Degree, UniOfGrad = @UniOfGrad, YearOfGrad = @YearOfGrad, Gender = @Gender, YearOfMsc = @YearOfMsc, PlaceOfMsc = @PlaceOfMsc, PlaceOfPhd = @PlaceOfPhd, YearOfPhd = @YearOfPhd, Language = @Language, Role = @Role, Address = @Address, Phone = @Phone, Email = @Email, Status = @Status, MajorID = @MajorID FROM Professor INNER JOIN Major ON Professor.ID = Major.HeadOfMajor">
            <SelectParameters>
                <asp:ControlParameter ControlID="lbUsername" DefaultValue="" Name="username" PropertyName="Text" />
            </SelectParameters>
            <UpdateParameters>
                <asp:Parameter Name="Name" />
                <asp:Parameter Name="DateOfBirth" />
                <asp:Parameter Name="PlaceOfBirth" />
                <asp:Parameter Name="Degree" />
                <asp:Parameter Name="UniOfGrad" />
                <asp:Parameter Name="YearOfGrad" />
                <asp:Parameter Name="Gender" />
                <asp:Parameter Name="YearOfMsc" />
                <asp:Parameter Name="PlaceOfMsc" />
                <asp:Parameter Name="PlaceOfPhd" />
                <asp:Parameter Name="YearOfPhd" />
                <asp:Parameter Name="Language" />
                <asp:Parameter Name="Role" />
                <asp:Parameter Name="Address" />
                <asp:Parameter Name="Phone" />
                <asp:Parameter Name="Email" />
                <asp:Parameter Name="Status" />
                <asp:Parameter Name="MajorID" />
            </UpdateParameters>
        </asp:SqlDataSource>
    </p>
</asp:Content>
